import { decrypter, encrypter, subkeyconstructioner } from "./DES"
import { HexToBinary, binaryToHex, getBinary, getBuffer, to16 } from "./DES/utils"

// const text = " "
const text = `Yesterday is history. Tomorrow is a mystery. But today is a gift. That is why it's called the present! —— From Kung Fu Panda`
const buffer = getBuffer(text)
// console.log(text);


const arr = HexToBinary(buffer)
let hex = binaryToHex(arr)
// console.log(hex);

// 000000000000

const KEY = 'inspired'
const K = HexToBinary(getBuffer(KEY))
console.log(getBuffer(KEY));

// // 子密钥组
const subKeys = subkeyconstructioner(K)


const C1 = encrypter(text, subKeys)
console.log(C1);

// 9f5dd159d37432d905a879b60ccc14b9cd38a732f03eabeb7f001ef984510d9bdc32d65b5908e347c890818ce72b4866b85a46b354c5ad2112637b0fe7b3dff1d427f1a39536788d42a79bdcbcaf16743a84b276cc0ac85fae567020b7b6eb679d90b0a2d192f0991cdc00b3e4ffac2b2b5f7538f3514cfb8c1ae2482ef843be
// 9f5dd159d37432d905a879b60ccc14b9cd38a732f03eabeb7f001ef984510d9bdc32d65b5908e347c890818ce72b4866b85a46b354c5ad2112637b0fe7b3dff1d427f1a39536788d42a79bdcbcaf16747c40b3e9b9622c4cc20cfc972f70da75c661ffac2ca51098f4a4cfc4ca5032af9c50b9651d36dfc5cd222fb221b30d3e
const re = decrypter('9f5dd159d37432d905a879b60ccc14b9cd38a732f03eabeb7f001ef984510d9bdc32d65b5908e347c890818ce72b4866b85a46b354c5ad2112637b0fe7b3dff1d427f1a39536788d42a79bdcbcaf16747c40b3e9b9622c4cc20cfc972f70da75c661ffac2ca51098f4a4cfc4ca5032af9c50b9651d36dfc5cd222fb221b30d3e', subKeys)
// console.log(re);
slip(C1)
function slip(text: string) {
  for (let i = 1; i <= 16; i++) {
    console.log(text.substring((i - 1) * 16, i * 16), i);

  }
}



